import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getUserInfoService } from '@/api/user'

// 用户模块
export const useUserStore = defineStore(
  'user',
  () => {
    // 定义 token
    const token = ref('')
    // 设置 token
    const setToken = (t) => (token.value = t)
    // 封装数据
    const user = ref({})
    const getUser = async () => {
      const res = await getUserInfoService()
      user.value = res.data.data
    }
    const setUser = async (obj) => {
      user.value = obj
    }
    return { token, setToken, getUser, user, setUser }
  },
  { persist: true }
)
